﻿//-----------------------------------------------------------------------
// <copyright file="IClientSession.cs" company="FastNET Services">
//     Copyright (c) 2008-2009. All Rights Reserved.
// </copyright>
// <license>
//     GPLv2
// </license>
// <warranty>
//     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
//     BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
//     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
//     DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//     OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// </warranty>
//-----------------------------------------------------------------------
#region Usings

using System;
using GateShift.Services.SDK.Threading;

#endregion

namespace GateShift.Services.SDK.Services
{
    /// <summary>
    /// Interface for managing a single client session
    /// </summary>
    public interface IClientSession
    {
        /// <summary>
        /// Gets the ID of the session
        /// </summary>
        Guid SessionID { get; }

        /// <summary>
        /// Gets the total time the user has been online during this session
        /// </summary>
        TimeSpan SessionTime { get; }

        /// <summary>
        /// Gets a dictionary of session properties for this session
        /// </summary>
        ThreadedDictionary<string, object> Properties { get; }

        /// <summary>
        /// Gets a value indicating whether or not this user is logged into the system currently
        /// </summary>
        bool IsLoggedIn { get; }

        /// <summary>
        /// Gets the date the authentication token will expire
        /// </summary>
        DateTime TokenExpirationDate { get; }

        /// <summary>
        /// Gets the time left for this session's authentication token
        /// </summary>
        TimeSpan TokenExpirationLifeTime { get; }

        /// <summary>
        /// Gets the current authentication token for this session.
        /// Null signifies the session is not authenticated
        /// </summary>
        byte[] SessionToken { get; }

        /// <summary>
        /// Disconnects this client
        /// </summary>
        void Disconnect();

        /// <summary>
        /// Sends a set of data to the client
        /// </summary>
        /// <param name="serviceID">Client Service ID to talk to</param>
        /// <param name="serviceCode">Client Service Code to send</param>
        /// <param name="data">Serialized Data for the client</param>
        /// <param name="encrypt">Whether or not to encrypt the data to the client</param>
        void SendData(byte serviceID, byte serviceCode, byte[] data, bool encrypt);

        /// <summary>
        /// Creates or renews the authentication token for this session
        /// </summary>
        void RenewSessionToken();

        /// <summary>
        /// Clears the authentication token for this session
        /// </summary>
        void ClearSessionToken();

        /// <summary>
        /// Expires the authentication token for this session
        /// </summary>
        void ExpireSessionToken();
    }
}